<!-- 
@todo 好像不是这么一回事。
身份类型： 
身份类型的可靠值有省代理，市代理，分公司，联合创始人。
如果是省代理，
-->
<template>
	<view class="wc-box">
		<view class="sf-label"  @click="open">
			<slot></slot>
		</view>
		<u-verification-code seconds="60" ref="uCode" @change="codeChange"></u-verification-code>
		<u-popup v-model="show2" mode="center" border-radius="20" @maskClick="maskClick">
			<view class="activation-1">
				<view class="activation-tm">
					激活达人
				</view>
				<view class="activation-nr">
					<view class="display-flex iosx">
						<view class="yzmiosx">激活码:</view>
						<input  class="inputis" v-model="users_code"  placeholder="激活码" />
					</view>
					
					<view class="display-flex iosx" style="margin-top: 30rpx;">
						<view class="yzmiosx">验证码:</view>
						<input  class="inputis" v-model="code"  placeholder="区代或合伙人的验证码"/>
						<view class="huoqyzm" @click="getCode">{{ codeTips }}</view>
					</view>
					<button @click="activeUsersCode" class="butqd">确定</button>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		props: {},
		data(){
			return {
				show2: false,
				codeTips: '',
				code: '',
				users_code: ''
			}
		},
		methods: {
			open(){
				this.show2 = true
			},
			maskClick(){
				console.log(e);
			},
			codeChange(text){
				this.codeTips = text;
			},
			getCode(){
				if (this.$refs.uCode.canGetCode) {
					if(this.users_code == '') {
						this.$u.toast('请输入您申请的激活码');
						return;
					}
					// 向后端请求验证码
					this.$u.post('publics/api.sms/sendCode?type=active_users_code&users_code=' + this.users_code).then(res => {
						if(res.code == 1) {
							this.$refs.uCode.start();
						}
					})
				} else {
					this.$u.toast('倒计时结束后再发送');
				}
			},
			activeUsersCode() {
				if(this.users_code == '') {
					this.$u.toast('请输入激活码');
					return;
				}
				
				if(this.code == '') {
					this.$u.toast('请输入区代或合伙人给您的验证码');
					return;
				}
				
				// 向后端请求验证码
				// @todo 这段代码 是从 芒播里抠过来的，还需要联调
				this.$u.post('member/api.users/activeUser', {
					users_code: this.users_code,
					code: this.code
				}).then(res => {
					if(res.code == 1) {
						this.getCenterInfo();
						this.users_code = this.code = '';
						this.$u.toast('激活成功');
						this.show2 = false;
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.wc-box {
		min-width: 90rpx;
		line-height: 30rpx;
		font-size: 22rpx;
		color: #ffffff;
		background-color: #E38F4A;
		border-radius: 6rpx;
		padding: 2rpx 10rpx;
		display: inline-block;
		text-align: center;
		margin-left: 10rpx;
		background-color: #3c9cff;
	}
</style>